﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.Protocol;
using ServerBase.Other;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using UtilLib;
using System;
using static ServerBase.Config.Conf;
using ServerBase.Config;
using System.Collections.Generic;
using ServerPublic.Data;
using System.Linq;
using ServerPublic.Manager;
using static ServerGame.Manager.Efun;
using ServerGame.Manager;
using System.Text.Json.Serialization;

namespace ServerGame.GameObject
{
    /// <summary>
    /// 通用方法
    /// </summary>
    partial class Player
    {
        //唯一Id
        public long Puid { get => Uid; set => Uid = value; }

        public string Name { get => DaBasic.Name; set => DaBasic.Name = value; }
        public string Gender { get => DaBasic.Gender; set => DaBasic.Gender = value; }
        public string Family { get => DaBasic.Family; set => DaBasic.Family = value; }
        public string Title { get => DaBasic.Title; set => DaBasic.Title = value; }
        public ConfigFamily CfgFamily => ConfFamily[Family];
        public int Age { get => DaBasic.Age; set => DaBasic.Age = value; }
        public int Level { get => DaCommon.Level; set => DaCommon.Level = value; }
        public EClasss Classs => ((EClasss)(CfgFamily.Classs));

        public string Desc => $"{Title} {CfgFamily.ColorSp()}{Family}弟子{NOR} {Name} ({Puid})";

        //IP地址
        [JsonIgnore]
        public string IpAddress => Session.IpAddress();

        //判断气血和内力越界
        public void CheckMax()
        {
            this[EProp.efkee] = Math.Clamp(this[EProp.efkee], 1, this[EProp.mxkee]);
            this[EProp.efsen] = Math.Clamp(this[EProp.efsen], 1, this[EProp.mxsen]);
            this[EProp.kee] = Math.Clamp(this[EProp.kee], 1, this[EProp.efkee]);
            this[EProp.sen] = Math.Clamp(this[EProp.sen], 1, this[EProp.efsen]);
            this[EProp.force] = Math.Clamp(this[EProp.force], 0, this[EProp.mxforce] * 2);
            this[EProp.mana] = Math.Clamp(this[EProp.mana], 0, this[EProp.mxmana] * 2);
        }
        //根据经验计算出等级
        public int LevelSetup()
        {
            Level = Exp2Level(DaCommon.Exp);
            return Level;
        }
        public override int this[EProp prop]
        {
            get
            {
                int val = 0;
                switch (prop.PropType())
                {
                    case EPropType.basic:
                        this.DaCommon.DictProp.TryGetValue((int)prop, out val);
                        break;
                    case EPropType.adj:
                        this.DaTemp.DictTemp.TryGetValue((int)prop, out val);
                        break;
                    default:
                        break;
                }
                return val;
            }
            set
            {
                switch (prop.PropType())
                {
                    case EPropType.basic:
                        this.DaCommon.DictProp[(int)prop] = value;
                        break;
                    case EPropType.adj:
                        this.DaTemp.DictTemp[(int)prop] = value;
                        break;
                    default:
                        break;
                }
            }
        }
        public override long this[EPropCbt propcbt]
        {
            get
            {
                return this.PropCbt(propcbt);
            }
            set
            {
            }
        }

    }
}